home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)G / (A)G6.ADF / docs < prev    next >
Text File  |  1988-05-25  |  53KB  |  1,849 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.                 BATTLE DROIDS INSTRUCTIONS MANUAL
  11.                          By Gregg Jacobs
  12.  
  13.                             Contents:
  14.                          
  15.  
  16.  
  17. 1 :  Introduction
  18.  
  19. 2 :  Running the Arena
  20.  
  21. 3 :  Droid Hardware
  22.  
  23. 4 :  Programming Droids
  24.  
  25. 5 :  The Compiler
  26.  
  27. 6 :  The Battle Droids Arena
  28.  
  29. 7 :  Droid Instructions Summary
  30.  
  31. 8 :  Example Droid Program, Arthur
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.                         1 :  Introduction
  74.  
  75.  
  76.  
  77.     Battle droids  is  a  game  of  artificial  intelligence  and
  78. survival.  Your job is  to  design,  build,  and  program a droid
  79. which is intelligent  and  deadly  enough  to survive in an arena
  80. filled with enemy droids which  were  made  by other people whose
  81. job is the same as yours.
  82.  
  83.      Your droid will be sent to the Battle  Droids Arena where it
  84. must fight, or die.   Opposing  droids  have  been  programmed by
  85. other people to find  droids  and  destroy  them.  Thus, you must
  86. make a better droid, one that will find the enemy droid before it
  87. finds yours.
  88.      To build your droid, you must first  buy a  cpu for it.  The
  89. cpu is the brain of the droid;  it  will execute the instructions
  90. in the program  you  later  write  for  the  droid.  There exists
  91. several different cpu's  that  run  at  different speeds.  If you
  92. want your droid to be able to move about the arena, you may buy a
  93. drive for it; there  are  several  different  types  that move at
  94. different speeds.  To be able to destroy the (hopefully) inferior
  95. droids in the arena, you will need  to buy a few weapons and some
  96. ammunition for the weapons.  There are expensive weapons that can
  97. devastate another droid   in a few  good shots, there are weapons
  98. with shots that move at higher speeds so that it is easier to get
  99. a good shot in.  You may also buy armor to protect your drive and
  100. weapons.  This is always a good  idea,  since the other droids in
  101. the arena will not simply short circuit  themselves  out of fear.
  102. They are in the arena with the  same  purpose  as you: TO DESTROY
  103. ALL OTHER DROIDS.
  104.                      
  105.     All of this hardware is of no  practical  use however, unless
  106. you have something to run it.   This  is the program's job.  Once
  107. you have decided on what hardware you want your droid constructed
  108. out of, you must tell the droid what  to do with it.  The program
  109. gives the droid a set of  instructions  to  follow once it is the
  110. arena.  The program tells the droid  where to scan with its radar
  111. to find other droids, where to  fire  once it has found them, and
  112. what to do if it gets hit.  The  droid  and  its program are made
  113. entirely before the droid  is  put  into  the arena.  Once in the
  114. arena, all the droid can do  is let  the cpu execute the program,
  115. for better or worse.
  116.  
  117.     To make your droid, simply type  the  definition for the cpu,
  118. drive, weapons, armor, and program  into a file.  Any editor will
  119. work as long as it writes to  the  file  in ASCII (that is, plain
  120. normal text).  Once the hardware is  defined in the file, and the
  121. program is written in, the file is  compiled.  The compiler reads
  122. the file you just made, and  interpretates  it so that your droid
  123. may now be put in the arena.
  124.  
  125.     How well your droid does relative to other droids is measured
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139. by its score.  There are two  scores  kept  for each droid in the
  140. arena.  The first  is  the  score  for  the  current battle.  The
  141. second score is the droid's  running  average score.  The running
  142. average score includes the score for  the current battle, so both
  143. scores increase as your droid  does  damage,  however the average
  144. score increases more slowly because  it is averages with previous
  145. scores.
  146.  
  147.     The current score is based on two things:     how much damage
  148. your droid causes, and its cost.   Points are awarded as follows:
  149. for each point of damage your droid  causes, it gets a point, for
  150. each droid that is destroyed while your droid is still running in
  151. the arena, your droid gets 30 extra points.  The number of points
  152. obtained by your droid  is  divided  by  the  square of its cost.
  153. This requires a droid to be extremely  viscious, yet inexpensive.
  154. The idea is to get as much bang  for  the  buck as possible.  The
  155. actual equation for calculating score is:
  156.  
  157.                    16000000.*points/(cost*cost)
  158.  
  159. The number 16000000. is  included  to make the score a reasonable
  160. number from 0. to 1000.  As you  can  see, a more expensive droid
  161. will have a lower score than a less  expensive droid if they both
  162. obtained the same number  of  points.   Every  time  the droid is
  163. compiled, the value for its average score is set to 0. 
  164.  
  165.     Thus, destroy as many  enemy  droids  as  possible, and do it
  166. with as  little  money  as  possible.  Anyone  can  buy  the best
  167. weapons, all the ammunition they need, and as much armor as could
  168. be imagined.  No one is impressed  by a $10000 droid destroying a
  169. $2000 droid; one would hope it  would  be  able to.  Great droids
  170. need  something   more.    They   need   a   program;  they  need
  171. intelligence.   Remember,  "The  sharpest  blade  is  not  always
  172. enough." (Highlander)
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.                      2 :  Running the Arena
  206.  
  207.  
  208.  
  209.     To begin running a few  battles  right  away  between several
  210. droids, go to CLI on the Amiga, and type:
  211.  
  212.     bat n d1 d2 d3 ...
  213.  
  214.     Where n is the number of battles to  run.  n may be from 1 to
  215. 99.  d1 d2 d3 ... is the list of the names of the droids you want
  216. to put in the arena.  You may place  up to eight in, but you must
  217. put in at least two.
  218.  
  219.     The battles will be run  consecutively  until finished.  When
  220. all battles are done running,  click  on  the Q icon on the upper
  221. right side of the status panel to quit.
  222.  
  223.     The Battle Droid Arena  may  also  be  started by typing from
  224. CLI:
  225.  
  226.     battle
  227.  
  228.     This will bring up a window  showing  the available droids in
  229. the left column under the  heading  "AVAILABLE".   You may scroll
  230. through the list of available  droids  by  clicking on the up and
  231. down arrows between the AVAILABLE  and SELECTED columns.  To pick
  232. one to put in the arena, click  on  its  name.  This will put its
  233. name in the list under  the  heading  "SELECTED".   If you change
  234. your mind, and don't want  to  run  the  droid, click on its name
  235. under the SELECTED column, and it will be removed.  The number of
  236. battles to run may be adjusted  by  using  the up and down arrows
  237. next to the display showing the  NUMBER  OF BATTLES TO RUN.  Once
  238. you have selected  all  the  droids  you  wish  to  run, and have
  239. selected the number of battles, click  on RUN.  If you've changed
  240. your mind, click on the window's close gadget.
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.                        3 :  Droid Hardware
  272.  
  273.  
  274.  
  275.     This section describes all  the  hardware  available  to your
  276. droid, its function, and most importantly its cost.
  277.  
  278.                               CPU'S
  279.  
  280.     Every droid needs a cpu.  This component is required. The cpu
  281. is the brain of a droid.  The  more  expensive  cpu's can execute
  282. instructions in the  program  faster.   The  cpu's  available are
  283. shown  below  with  their  cost  and  relative  execution  speed.
  284. Execution speed will  be  discussed  further   in  the section of
  285. Instructions Summary.
  286.  
  287. cpu type      cost       relative speed measured in 
  288.                          operations every
  289.                          1/10 of a second
  290.  
  291.   8bit        $100       9
  292.   16bit       $200       14
  293.   32bit       $400       18
  294.   2x16bit     $600       22
  295.   2x32bit     $1000      25
  296.  
  297.     To define the cpu for your droid, typethe following line into
  298. your droid file:
  299.  
  300. cpu 2x16bit
  301.  
  302.     This will give your droid a  2x16bit  cpu which will add $600
  303. to the total cost of your droid.
  304.  
  305.  
  306.                              DRIVES
  307.  
  308.     While the drive is not a required  component of a droid as is
  309. the cpu, it is highly  recommended.   Once your droid is located,
  310. it will be an easy task to  destroy  it  if it does not move to a
  311. new location.  The drive units, speeds, accelerations, costs, and
  312. basic armor are shown below.   The  basic armor is how much armor
  313. comes with the drive for  free.    This  is just a measure of how
  314. tough the drive naturally is.  Additional armor may be added at a
  315. cost of $7 for each unit.
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337. drive     cost  basic armor    top speed      acceleration
  338. type                          (meters/sec)  (meters/sec/sec)
  339.  
  340. none       $0    0              0.             0
  341. budget     $200  10             5.             1.0
  342. track      $500  60             10.            2.0
  343. wheel      $500  30             14.            1.5
  344. hover      $500  15             18.            1.0
  345. turbohover $700  5              20.            1.5
  346.  
  347.     To define a drive, put the following line in your droid file:
  348.  
  349. drive track 20
  350.  
  351.     This gives you a track  type  drive  with  20 armor units (in
  352. addition to its basic 60 units).
  353.  
  354.     The "none" type drive exists so that you can simply add armor
  355. to your droid.  The "budget"  drive  is a simple small flimsy car
  356. type chassis, kind of like a  Hyudail.   The "track" is a pair of
  357. tank treads (very tough) from surplus army Sherman tanks, "wheel"
  358. is a three wheel solid rubber tire drive, "hover" is a hovercraft
  359. (fairly flimsy  and  easily  stopped),  "turbohover"  is  a  more
  360. powerful and lighter version of the basic hover.
  361.  
  362.                             REGISTERS
  363.  
  364.     When writing a program for a droid, you may find it useful to
  365. have your program save numbers  for  later  use.  Your droid will
  366. need some memory  to  store  these  numbers  in.   This memory is
  367. created in the form of storage registers.  Each register costs $2
  368. for the extra memory.  To  define  some storage registers in your
  369. program, type:
  370.  
  371.     reg 23
  372.  
  373.     This will give you 23 storage registers  to store numbers in.
  374. The registers are numbered 0 to 22.
  375.  
  376.                              WEAPONS
  377.  
  378.     If you plan on destroying other  droids  and  getting points,
  379. you will probably want to buy a  weapon  or two.  You may have up
  380. to four weapons (numbered 0 to 3) on your droid. To get a weapon,
  381. you need to specify the type, how  much armor you want protecting
  382. it, and how much  ammunition  you  want  to  have for it to fire.
  383. Below are the available  weapons,  their cost, the speed of their
  384. shots, the cost for ammunition, how  long it takes for the weapon
  385. to reload (so that it may fire  again),  and  how much damage the
  386. shot does on average.
  387.  
  388.   
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403. weapon  cost  shot speed    ammo cost  reload time  average
  404.  type        (meters/sec)   (per shot) (seconds)    damage
  405.  
  406. lgun    $150  100           $1          .6           7
  407. mgun    $225  80            $2          .8           12
  408. hgun    $300  60            $3         1.0           17
  409. arail   $100  70            $5          .8           15
  410. brail   $150  60            $8         1.0           20
  411. crail   $200  50            $10        1.2           25
  412. laser   $400  instant       $5         1.0           15
  413. proton  $800  instant       $10        2.0           30
  414.  
  415.     To define a weapon type the  following  line  into your droid
  416. file:
  417.  
  418. weapon laser 10 50
  419.  
  420.     This will give you a laser with  10  armor, and 50 shots.  As
  421. always the cost of armor is $7 for each point.  So the total cost
  422. of this weapon is $720 ($400  for  the  laser, $70 for armor, and
  423. $250 for ammo).
  424.  
  425.     The lgun is light caliber gun, the mgun a medium caliber, and
  426. the hgun a heavy caliber. The  guns  fire  explosive shells which
  427. can be set to explode after traveling  a specified distance.  The
  428. shrapnel from this  explosion  can  cause  damage to droids.  The
  429. damage will be  less  than  a  direct  hit,  but  is  better than
  430. nothing.  An arail is a  rocket  lauching  rail  that is made for
  431. small rockets, brails are for medium  rockets, and crails are for
  432. heavy rockets.  Each rocket is like  the shells in that it may be
  433. set to explode at a certain  distance.   The  warheads carried on
  434. the rockets are much larger than those on shells, however rockets
  435. take much longer to arrive at  their  targets because they travel
  436. slower.  The ammunition for the rocket rails also costs more than
  437. the gun ammo.  The laser is a  chemically  activated laser;  each
  438. shot uses up a cartidge of  chemicals.  The  proton is a particle
  439. beam left over from SDI.
  440.  
  441.  
  442.     Note:  The only piece of  hardware  that  you are required to
  443. buy is a cpu.  You don't have to buy anything else, but the other
  444. things really are very useful.  A fast moving drive allows you to 
  445. dodge shots more easily if you  keep  moving;  of course shooting
  446. is much more difficult if you are  moving.  When you find another
  447. droid while you are moving, you will need to correct for the fact
  448. that you have moved from the time you found the droid to the time
  449. you actually fire.  The type of weapon  can also help in hitting.
  450. If you are firing at a moving droid, you will probably hit with a
  451. laser   or   proton   because   the   shot   reaches  the  target
  452. instantaneously.  However, if you fire at a moving droid with a C 
  453. type rocket, the rocket  will  probably  miss  because the target
  454. will have moved by the time the rocket  arrives.  In addition, if
  455. a laser or proton miss, they will hit the wall, most probably not
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469. hurting anything.  If a  rocket  or  shell  misses, if your droid
  470. took the time to tell the shell to explode at the distance to the
  471. other droid, it may  still  cause  damage.  Of  course lasers and
  472. protons are  very  expensive,  and  will  decrease  your score by
  473. costing more than other weapons.
  474.  
  475.     Also, be careful to buy enough ammunition  to keep your droid
  476. going for  the  entire  battle.    Droids  are  reloaded  between
  477. battles, but it is very embarrassing to have your droid destroyed
  478. because your droid thought it was blasting away at something, but
  479. was actually out of ammo.
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.                      4 :  Programming droids
  536.  
  537.  
  538.  
  539.     To create a droid program, type the  definitions for the cpu,
  540. drive, weapons, registers, and the instructions for it to execute
  541. into your droid file.  You can use  any editor to do this as long
  542. as the editor writes its output  to  the  file in ASCII (that is,
  543. normal readable characters).  The ED text editor is good for this
  544. on the Amiga.  This droid must then be compiled.  For example, if
  545. you write your droid to a file called "fred", type:
  546.  
  547. comp fred
  548.  
  549.     This will compile fred, and create aversion called "fred.drd"
  550. that the arena uses.  More on the compiler later.
  551.  
  552.     To program a droid  you  must  understand  the  language  the
  553. droids use.  Droids  are  programmed  in  Reverse Polish Notation
  554. (RPN).  This language is  very  efficient  in  terms of execution
  555. speed, but must be understood  to  be used.  Normal notation used
  556. in   most  programming  languages  is  arithemetic  notation.  In
  557. arithmetic notation, you may write an equation as:
  558.                      (5+3)
  559.                      -----
  560.                      (3+1)
  561.  
  562.     The answer is 2.  In RPN, the same equation is written as:
  563.         # 5, # 3, +, # 3, # 1, +, /
  564.  
  565.     To understand this, let's look at  how the cpu executes these
  566. instructions.  A  register  is  a  place  where  a  number may be
  567. stored.  The cpu is made up of  three  registers that numbers are
  568. stored  in;  they  are   called   the  x,  y,  and  z  registers.
  569. Collectively they are called  the  "stack".  This is because they
  570. can be visualized as being stacked on top of each other:
  571.  
  572.                 z register
  573.                 y register           The Stack
  574.                 x register
  575.  
  576.     Some terms commonly  used  with  the  stack  are  "push"  and
  577. "drop".  When the stack is "pushed",  the value in the z register
  578. is lost, the value in the y register is put into z, and the value
  579. in the x register is put into y.  This is visualized as the stack
  580. being pushed up, with z falling off the top:
  581.  
  582.                z   lost   /------- z
  583.                y --------/  /----- y     Pushing the stack
  584.                x ----------/    /- x
  585.                     new value--/
  586.       "Dropping" the stack means  performing  some operation on x
  587. and y (such as adding  them),  and  putting  the  result in the x
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601. register, the z value is  then  put  into  the  y register.  This
  602. can be visualized as the stack  dropping  down (note, the z value
  603. is unchanged):
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.                z ------\---------- z
  668.                y -\     \--------- y     Dropping the stack
  669.                x --- operation---- x
  670.  
  671.     Now, back to the example: (5+3)/(3+1).   This is what happens
  672. to the stack as the RPN instructions  ( # 5, # 3, +, # 3, # 1, +,
  673. /) are executed.  Assume x, y, and z start with the value of 0 in
  674. each:
  675.  
  676. z = 0    The first instruction, "# 5", pushes the    z = 0
  677. y = 0    stack up, and puts 5 in the x register.     y = 0
  678. x = 0    the resulting stack is shown on the right:  x = 5
  679.  
  680. The next instruction, "# 3", again pushes the stack  z = 0
  681. and puts the number 3 in the x register:             y = 5
  682.                                                      x = 3
  683.  
  684. "+" is a stack dropping instruction.  That is, it    z = 0
  685. operates on x and y, puts the result in x, and       y = 0
  686. drops z into y.  The result is shown:                x = 8
  687.  
  688. "# 3" will push the stack again, and put the         z = 0
  689. value of 3 into x:                                   y = 8
  690.                                                      x = 3
  691.  
  692. "# 1" pushes the stack, and puts 1 in the x          z = 8
  693. register.  Note how the 8 which was in y is first    y = 3
  694. put into z, and the 3 in x was put into y before     x = 1
  695. the 1 is put into x.
  696.  
  697. "+" again will drop the stack.  It adds x and y,     z = 8
  698. puts the result in x, then drops the value in z      y = 8
  699. into the y register.  Note the z value is unchanged. x = 4
  700.  
  701. "/" is another stack drop instruction.  It divides   z = 8
  702. y by x, puts the result into the x register, and     y = 8
  703. drops z into y.                                      x = 2
  704.  
  705.     Now the answer, 2, is in the x register.  Look again how this
  706. worked.  First, 5 and 3 are  added.   Second,  3 and 1 are added.
  707. Last, the result of the  first  is  divided  by the result of the
  708. second.
  709.  
  710.     Some instructions affect only  the  x register.  For example,
  711. "sin" will take the sine of the  value  in the x register and put
  712. the result back into the x register.   These instructions leave y
  713. and z unchanged.  In  the  section  on  Instructions  Summary the
  714. exact effect of  each  instruction  on  the  stack is given.  The
  715. concepts of pushing and  dropping  the  stack are very important,
  716. and should be well understood  in  order  to become proficient at
  717. programming RPN.
  718.  
  719.     The first thing you probably will want your droid to do is to
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733. find a target.  To do this, it  is  easiest to use the radar that
  734. comes with your droid.  To use it, the radar needs a direction to
  735. scan, and a  beam  width.   The  direction  is  measured  counter
  736. clockwise with 0  being  straight  right,  and the beam  width is
  737. measured to either side of the  scan  direction.   The radar gets
  738. this information from the  stack.   The scan angle is taken to be
  739. the number in the x register,  and  the beam width is taken to be
  740. the number in the y register.   The  value in the x register will
  741. be changed to the distance  to  the  closest  droid  in the radar
  742. beam.  If there is no droid in the  beam, a value of -1 is put in
  743. the x register.  For  example  to  scan  straight up (90 degrees)
  744. with a beam width of 10  degrees,  put the following instructions
  745. in your program:
  746.  
  747. # 10, # 90, radar
  748.  
  749.     The first instruction, "# 10",  will  push  the stack up, and
  750. put 10 in the x register.  "# 90"  will push the stack up, the 10
  751. will go into to y  register,  and  90  will be put in x.  "radar"
  752. will then scan at 90  degrees  (in  the  x  register) with a beam
  753. width of 10 degrees (in the  y  register).   The  value  in the x
  754. register will then  be  changed  to  either  the  distance to the
  755. closest droid within the beam, or -1 if no droid was in the beam.
  756. The following diagram for  this  example  may  help  clear up any
  757. misunderstadings:
  758.  
  759.                             90 degrees
  760.                         |      |      |____
  761.                          |     |     /     \    This droid will
  762.                          |     |    | other |   be detected
  763.                           | 10 | 10  \droid/
  764.                           |    |    |
  765.                            |   |   |
  766.                            |   |   |
  767.                             |  |  |        beam width=10
  768.                             |  |  |        (in y register)
  769.                              | | |
  770.                              |   |         scan angle=90
  771.                               | |          (in x register)
  772.                              __|__  
  773.  180 degrees                /scan-\                 0 degrees
  774.   -----------------------  | ning  |  --------------------------
  775.                             \droid/
  776.                               
  777.  
  778.     Of course, you may want to look  in  more than one direction.
  779. This is easily accomplished if you use a storage register to hold
  780. the scan angle.   For  example,  assume  you  have  at  least one
  781. register available:
  782.  
  783. # 0, sto 0
  784. label start
  785. # 10, sto+ 0
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799. # 5, rcl 0, radar
  800. goto start
  801.  
  802.     There are a few new  instructions  here  that need explaining
  803. first.  "sto 0"  will  change  the  number  in  register 0 to the
  804. number in x; it does not change  the  stack.   "label start" is a
  805. label.  This marks a place  in  the  program.   The  "goto start"
  806. later on will cause  execution  to  jump  back to the instruction
  807. following the label.  Any six  character  name may follow a label
  808. instruction.  The "sto+ 0" adds  the  number in the x register to
  809. the number in register 0,  and  puts  the  result  in register 0.
  810. "rcl 0" pushes the stack, and puts  the number in register 0 into
  811. the x register.
  812.  
  813.     So what does this do?  First, 0 is pushed onto the stack, and
  814. then stored into register 0.   The  "label start" is ignored.  "#
  815. 10" pushes 10 onto the stack,  and  stores  10 plus register 0 in
  816. register 0.  This increments register  0 by 10.  "# 5" pushes the
  817. stack, and puts 5 in x.  "rcl  0"  pushes the stack, and puts the
  818. value in register 0 in the x register.  "radar" then looks with a
  819. 5 degree beam width (in  y  register)  in  the direction of the x
  820. register which was  recalled  from  register  0.  Next, the "goto
  821. start" is executed.  The next instruction  to be executed will be
  822. the one following  "label  start",  i.e.  "# 10".  This will keep
  823. adding 10 to register 0, and using it as a scan angle.  Thus each
  824. time through it looks 10 degrees further counter clockwise.
  825.  
  826.     Now how do you make it  fire?   Here  comes  several more new
  827. instructions, so get ready:
  828.  
  829. cpu 16bit           \ Give it a cpu to think. \
  830. weapon lgun 10 50   \ A light gun with 10 armor and 50 shots. \
  831. reg 2               \ Two storage registers allocated. \
  832. equate angle 0      \ Anywhere it sees "angle", replace with "0"\
  833. # 0, sto angle      \ Set angle to 0 degrees. \
  834. label start
  835. # 10, sto+ angle    \ Increment angle by 10 degrees. \
  836. # 5, rcl angle, radar  \ Scan at angle, width 5 degrees. \
  837.                     \ Remember, the radar returns the \
  838.                     \ distance to the droid in the x \
  839.                     \ register, or -1 if none is found. \ 
  840. x>0? goto fire      \ If x is greater than 0, goto fire. \
  841. goto start          \ Goto start, and keep looking. \
  842.  
  843. label fire
  844. sto dist            \ Distance to droid is still in x register. \
  845. rcl angle, aim      \ Aim in the proper direction. \
  846. rcl dist            \ Need distance to explode at in x. \
  847. fire 0              \ Fire the light gun (distance is in x).\
  848. goto start          \ Keep looking. \
  849.  
  850.     This is a complete droid, since it  has a cpu.  The weapon is
  851. defined as a lgun with 10 armor and  50 shots.  Two registers are
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865. given to it to store numbers  in.   Two  things are here that are
  866. very helpful to programming.  The  first is the "equate angle 0".
  867. This means that anywhere  the  word  "angle"  is seen, it will be
  868. replaced by "0".  Thus, "sto angle"  will be the same as "sto 0".
  869. This  allows  words  to  be  used  instead  of  numbers  for  the
  870. registers,  and  helps  you  make  programs  that  are  much more
  871. readable.  Second are comments.  Anything between a pair of "\"'s
  872. is ignored.  This allows you to  put  in comments to tell what is
  873. going on.  "x>0?" is a conditional test.  If x is greater than 0, 
  874. the next instruction ("goto fire") will be executed, otherwise it
  875. will be skipped.  Since radar returns the distance to a droid, or
  876. -1 if none is seen,  execution  will  jump  to  "label fire" if a
  877. droid is there, or will "goto  start"  if one isn't.  "aim" takes
  878. the number in the x register and turns  the turret containing the
  879. weapons to face that direction (0  degrees is straight right, and
  880. posative is measured counter clockwise).   "fire 0" will fire the
  881. light gun.   The  number  in  the  x  register  when  "fire 0" is
  882. executed will give the distance  for  the shot to explode at.  If
  883. you don't get a direct hit, you  may  still have the shot blow up
  884. nearby and cause damage.
  885.  
  886.     Movement can be done quite easily also.  All your droid needs
  887. to know is the direction it  wants  to go, and how fast.  This is
  888. done with "heading" and  "speed".   "heading"  takes the value in
  889. the x register, and faces the droid  in that direction .  Heading
  890. is measured positive  counterclockwise  (0  is straight right, 90
  891. up, 180 left, and 270 down).   "speed"  takes  the value in the x
  892. register,  and  starts  the  droid  moving  at  that  speed.  For
  893. example:
  894.  
  895. # 0, heading
  896. # 2, speed
  897.  
  898.     This will move the droid at a heading  of 0 degrees (straight
  899. right) at a speed of 2 meters/second.
  900.  
  901.     There are many more instructions to affect the droid, and for
  902. the droid to find  information  about  its  environment  (such as
  903. where it is in the arena,  if  it  has  been hit, etc.).  See the
  904. list of droid control and droid  environment  instructions  under
  905. the instruction summary section for more details.
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.                         5 :  The Compiler
  932.  
  933.  
  934.  
  935.     The compiler is used  to  transform  the  file which contains
  936. your program into something  that  can  easily be read and run by
  937. the Battle Droids Arena.  This section  gives details of compiler
  938. syntax and use.
  939.  
  940.     An instruction consists of  the  instruction  name  plus  any
  941. parameters it requires.  For example  "sto" must be followed by a
  942. register number.  All names and parameters must be separated by a
  943. separator character.   The  separator  characters  are the blank,
  944. carriage   return,   backspace,   tab,  comma,  and  colon.   All
  945. instructions must also  be  separated  by  a separator character.
  946. Thus the following are equivalent:
  947.  
  948. #:5 #:3 + #:3 #:1 + /
  949.  
  950. and
  951.  
  952. # 5
  953. # 3
  954. +
  955. # 3, # 1, +, /
  956.  
  957.     Comments are delimited by "\".  Any characters between a pair
  958. of "\"'s are ignored.
  959.  
  960.     The definitions for cpu, drive,  weapons,  and  registers may
  961. appear anywhere in the program, but  it is most convenient to put
  962. them at the beginning.
  963.  
  964.     To compile a droid, type from CLI on the Amiga:
  965.  
  966. comp [-f -n] d1 d2 d3...
  967.  
  968.     The -f is optional.  If used,  the  compiler will run faster,
  969. and the output on the screen  will  go  by faster.  The -n option
  970. will not print to  the  screen  at  all.   Use  only the -f or -n
  971. options, not both.  d2 d3... is a  list of droid names.  Whenever
  972. a droid is compiled, its  average  score is reset to 0.  Whenever
  973. an instruction in a droid  program  is changed, the droid must be
  974. recompiled.
  975.  
  976.     When the compiler reaches  an  unknown  instruction  in  your
  977. program, it will pause, show  you  what it doesn't understand and
  978. ask if it should continue.  Type "n" to have it stop.
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.                   6 :  The Battle Droids Arena
  1001.  
  1002.  
  1003.  
  1004.     This section describes the  arena  window,  the droid monitor
  1005. window, and damaging droids.  The  Battle Droids Arena is started
  1006. as described in  the  section  Running  The  Arena.   Below  is a
  1007. diagram of the arena and the Status Panel. 
  1008. _____________________________________________________________
  1009. |                                         | ___ ___ ___ ___ |
  1010. |                                         | |Q| |N| |P| |S| |
  1011. |                                         | --- --- --- --- |
  1012. |                                         |C name    $cost  |
  1013. |             C                           |-----------      |
  1014. |                                         | current/average |
  1015. |                                         |                 |
  1016. |                                         |C name    $cost  |
  1017. |                                         |-------          |
  1018. |                                         | current/average |
  1019. |                                         |                 |
  1020. |                                         |                 |
  1021. |                                         |                 |
  1022. |                                         |                 |
  1023. |                                         |  time:          |
  1024. |                                         | battles         |
  1025. -------------------------------------------------------------
  1026.  
  1027.  
  1028.  
  1029. A:  Status Panel.  Contains the Control Icons, Time Remaining,
  1030.     and the current status of all the droids in the arena.
  1031.  
  1032. B : Control Icons, clicking these has the following results:
  1033.       Q: This will quit the current sequence of battles, and
  1034.          and return to CLI.
  1035.       P: Pauses current battle until clicked again.
  1036.       N: End the current battle and go to the next one.
  1037.       S: Toggle the sound on and off.
  1038.  
  1039. C : Droid icon, name and cost.  Clicking on the droid icon will 
  1040.     open the droid monitor window for that droid.
  1041.  
  1042. D : Armor bar.  This shows the relative amount of armor remaining
  1043.     on a droid.  As armor is destroyed on a droid, the bar
  1044.     gradually shortens.  When the bars disappears, there is no 
  1045.     armor remaining on the droid.
  1046.  
  1047. E : Score.  The first number is the score obtained in the
  1048.     current set of battles.  The second is the average score
  1049.     obtained by the droid in its lifetime. Score is calculated as
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.     follows:
  1064.     
  1065.           16000000.*(points obtained)/(cost*cost)
  1066.     
  1067.     Points obtained is the total damage caused by the droid plus
  1068.     30 points for each droid destroyed while it was still
  1069.     operating.  The cost is shown next to the name.
  1070.  
  1071. F : Time Remaining.  When timer runs to 0, the battle is
  1072.     considered over.  No more points are awarded to any droids.
  1073.  
  1074.  
  1075.                       Droid Monitor Window
  1076.  
  1077.     The droid monitor window may be opened by clicking one of the
  1078. droid icons in the status  panel.   The  monitor window shows the
  1079. name of the droid it is monitoring,  the numbers contained in the
  1080. stack of the droid, and the instructions  the droid is executing.
  1081. This is a very useful device for debugging  a droid, and even for
  1082. learning the essentials of using the stack and RPN.
  1083.  
  1084.     There are two controls for the  monitor  window.  If the STEP
  1085. icon is clicked, execution will stop.  Each time the STEP icon is
  1086. clicked, the next instruction in the  droids program is executed,
  1087. the  list  of  instructions  is   pushed  up,  and  the  executed
  1088. instruction is shown on the  bottom  of  the list.  The resulting
  1089. stack is  also  displayed.   If  the  STEP  icon  is  held  down,
  1090. instructions will be executed at a slow pace.  Click the RUN icon
  1091. to resume execution of the program at normal speed. 
  1092.  
  1093.     The monitor window may be closed by clicking the close window
  1094. gadget, or by clicking  the  droid  icon  again.   If a different
  1095. droid icon is clicked, the  current  monitor window is shut down,
  1096. and a new one is opened for the most recently selected droid.
  1097.  
  1098.  
  1099.                          Damaging Droids
  1100.     
  1101.     Droids receive damage from three sources: running into walls,
  1102. running into  other  droids,  and  being  shot  by  other droids.
  1103. Hitting walls is usually avoidable,  running into other droids is
  1104. not always avoidable, and very little can stop another droid from
  1105. shooting at yours apart from destroying it first.
  1106.  
  1107.     The amount of damage that  is  done  depends  on  its source.
  1108. Damage from hitting walls and  other  droids depends on the speed
  1109. your droid is going when  it  hits.   The  faster  your droid was
  1110. moving when it hit the wall, the more  damage is done to it.  The
  1111. damage caused by different  types  of  weapons is given under the
  1112. section on Hardware.
  1113.  
  1114.     When a droid  takes  damage,  all  the  points  are  randomly
  1115. applied to the drive or one  of  the  weapons,  that  is only one
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129. thing will be hit.  Each point  of  damage will destroy one point
  1130. of armor.  Once all the armor  on  the drive or a weapon is gone,
  1131. the next hit on that particular  thing  will destroy it.  Weapons
  1132. operate at full function  until  destroyed,  but  the  drive will
  1133. gradually  loose  top   speed  as  its  original  base  armor  is
  1134. destroyed.  Once all  weapons  and  the  drive are destroyed, the
  1135. next hit will destroy the droid.
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.                  7 :  Droid Instructions Summary
  1196.  
  1197.  
  1198.                               
  1199.     Here is a synopsis of all the  droid  instructions available.
  1200. Each instruction also  shows  its  relative  execution time.  For
  1201. example, "+" takes 1 relative execution time for a cpu to run it.
  1202. An 8bit cpu may run 9 instructions  every 1/10 of a second.  This
  1203. means it may do 9 adds  every  1/10  of  a second, or 90 adds per
  1204. second.  Some instructions take longer  to execute.  For example,
  1205. "sto n" has an execution time of 3,  thus an 8bit cpu may execute
  1206. 3 "sto n" instructions in the same time it takes to execute 9 "+"
  1207. instructions.  The speed of a cpu also affects this.  An 8bit cpu
  1208. may run 9 adds in the same time  it  takes a 32 bit cpu to run 18
  1209. adds.  If you have a droid that  does  a  lot of thinking, it's a
  1210. good idea to give it a good cpu so  that it won't take all day to
  1211. think.
  1212.  
  1213.     Some instructions  take  more  memory  to  hold  than others.
  1214. Thus,  the  cost  of  each  instruction  differs.   The  cost  of
  1215. instructions is printed  out  next  to  each  instruction in your
  1216. program as it is compiled.
  1217.   
  1218. Here is how the functions are presented:
  1219.  
  1220. function name : stack effect : execution time : description
  1221.  
  1222. The letters used for stack effect are:
  1223. N : Instruction has no effect on stack.
  1224. P : Instruction pushes the stack up, puts something new in x. 
  1225. D : Instruction drops the stack down; the instruction
  1226.     will put the result of some operation on the x and y
  1227.     registers into the x register.
  1228. X : Instruction only changes x register of the stack;
  1229.     it leaves y and z unchanged.
  1230. U : The effect on the stack is unique to specific instruction,
  1231.     where it will be defined.
  1232.                                                     
  1233. equate s1 s2 :N:0: All subsequent occurrences of string s1 in the
  1234.               droid code will be replaced by string s2.  Only the
  1235.               first ten characters of s1 and s2 are used.  Up to
  1236.               100equates may be made.  Even instruction may be
  1237.               changed, for example:
  1238.                   equate define equate
  1239.               will allow you to use the word "define" instead of
  1240.               the word "equate" in all subsequent program
  1241.               instructions.
  1242.  
  1243.        ----- Droid Hardware Definition Instructions -----
  1244.  
  1245. reg n :N:0: Allocates n storage registers for your droid to use.
  1246.             The registers are numbered 0 to n-1.
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261. drive name n :N:0: Gives your droid a drive so that it can move.
  1262.               name is any valid drive type, and n is the amount
  1263.               of armor above the basic amount of armor (costs $7
  1264.               per point of extra armor).
  1265.  
  1266. cpu name :N:0: Give your droid a cpu to think of type name.
  1267.  
  1268. weapon name a s :N:0: Define a weapon.  name is any valid weapon
  1269.                type.  a is the amount of armor the weapon will
  1270.                have protecting it (costs $7 per point of armor).
  1271.                s is the number of shots the weapon will (cost is
  1272.                given in the section on Hardware).
  1273.  
  1274.             ----- Droid Mathematical Operations -----
  1275.  
  1276. + :D:2: Add the y and x registers, put the result in x.
  1277.  
  1278. - :D:2: Subtract y minus x, put the result in x.
  1279.  
  1280. * :D:4: Multiply y by x, put the result in x.
  1281.  
  1282. / :D:4: Divide y by x, put the result in x.
  1283.  
  1284. chs :X:1: Change sign of number in x.
  1285.  
  1286. y^x :D:8: Raise y to the x power, put the result in x.
  1287.  
  1288. lnx :X:8: Take the natural logarithm of x, put the result in x.
  1289.  
  1290. e^x :X:8: Raise base e to the x power, put the result in x.
  1291.  
  1292. sin :X:12: Take sine of x, put result in x.  x should be in
  1293.     degrees.
  1294.  
  1295. cos :X:12: Take cosine of x, put the result in x.  x should be in
  1296.     degrees.
  1297.  
  1298. tan :X:12: Take tangent of x, put the result in x. x should be in
  1299.     degrees.
  1300.  
  1301. asin :X:14: Take the arcsine of x, put the result x. (result in
  1302.      degrees)
  1303.  
  1304. acos :X:14: Take the arccosine of x, put result in x.  (result in
  1305.      degrees)
  1306.  
  1307. atan :X:14: Take the arctangent of x, put result in x. (result in
  1308.      degrees) Returns a result between -90 degrees and +90
  1309.      degrees.
  1310.  
  1311. atan2 :X:16:  Take arctangent of y register divided by x
  1312.       register. x may be 0.  Put result (in degrees) in x
  1313.       register, drop stack.  Returns a result between -180 
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.       degrees and +180 degrees.
  1328.  
  1329. r-d :X:3: Convert radians to degrees, put result in x.
  1330.  
  1331. d-r :X:3: Convert degrees to radians, put result in x.
  1332.  
  1333. 1/x :X:3: divide 1 by the x register, put the result in x.
  1334.  
  1335. sqrt :X:8: take the square root of x, put the result in x.
  1336.  
  1337. abs :X:2: take the absolute value of x, put the result in x.
  1338.  
  1339. int :X:2: Drop any fractional value from the number in x.
  1340.  
  1341. rnd :X:2: Round off the number in x.
  1342.  
  1343.         ----- Number Entry and Storage Instructions -----
  1344.  
  1345. pi :P:2: Put 3.141592654 in the x register.
  1346.  
  1347. ran :P:5: Put a random number between 0 and 1 in the x register. 
  1348.  
  1349. # number :P:1: Put number in the x register.
  1350.  
  1351. sto n :N:1: Put x register into storage register n.
  1352.  
  1353. rcl n :P:1: Put storage register n into x register.
  1354.  
  1355. sto+ n :N:4: Add storage register n plus the x register, put
  1356.        result in n.
  1357.  
  1358. sto- n :N:4: Subtract register n minus x, put result in n.
  1359.  
  1360. sto/ n :N:6: Divide register n by x, put result in n.
  1361.  
  1362. sto* n :N:6: Multiply register n by x, put result in n.
  1363.  
  1364. stoind n :N:2: Store indirect, store the x register in the
  1365.          register named by register n. e.g.: if register 5
  1366.          contains 10, then stoind 5 will store the x register
  1367.          into register 10.
  1368.  
  1369. rclind n :P:2: Recall indirect, recall to the x register, the
  1370.          register named by register n.
  1371.  
  1372. incr n :N:1: Increment register n by 1.
  1373.  
  1374. decr n :N:1: Decrement register n by 1.
  1375.  
  1376.               ----- Droid Stack Instructions -----
  1377.  
  1378. swap :U:2: Switch the values in the x and y registers.
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393. rup :U:2: Roll the stack up.  x goes to y, y to z, and z to x.
  1394.  
  1395. rdn :U:2: Roll the stack down.  z goes to y, y to x, and x to z.
  1396.  
  1397. enter :U:2: x is copied to y, y to z, and z to oblivion.
  1398.  
  1399. clst :U:2: Clear Stack.  Sets x, y, and z to 0.
  1400.  
  1401.                ----- Comparison Instructions -----
  1402.  
  1403. x=y? :N:2: if the x register equals the y register, perform the
  1404.      next instruction, otherwise skip it.
  1405.  
  1406. x>=y? :N:2: if x is greater or equal to y, perform the next
  1407.       instruction, otherwise skip it. 
  1408.  
  1409. x<=y? :N:2: if x is less or equal to y, perform the next
  1410.       instruction, otherwise skip it.
  1411.  
  1412. x<y? :N:2: if the x register is less than the y register, perform
  1413.      the next instruction, otherwise skip it.
  1414.  
  1415. x>y? :N:2: if the x register is greater than the y register,
  1416.       perform the next instruction, otherwise skip it. 
  1417.  
  1418. x!=y? :N:2: if the x register does not equal the y register,
  1419.       perform the next instruction, otherwise skip it. 
  1420.  
  1421. x=0? :N:2: if the x register equals 0, perform the next
  1422.      instruction, otherwise skip it. 
  1423.  
  1424. x>=0? :N:2: if the x register is greater or equal to 0, perform
  1425.       the next instruction, otherwise skip it. 
  1426.  
  1427. x<=0? :N:2: if the x register is less or equal to 0, perform the
  1428.       next instruction, otherwise skip it.
  1429.  
  1430. x>0? :N:2: if the x register is greater than 0, perform the next
  1431.      instruction, otherwise skip it.
  1432.  
  1433. x<0? :N:2: if the x register is less than 0, perform the next
  1434.      instruction, otherwise skip it.
  1435.  
  1436.            ----- Execution Control Instructions -----
  1437.  
  1438. goto name :N:1: Jump execution to the label name
  1439.  
  1440. gosub name :N:5: Jump execution to the label name.  When a return
  1441.            is encountered, execution will continue at the
  1442.            instruction following the gosub.  gosub's may be
  1443.            nested up to 10 levels deep.
  1444.  
  1445. label name :N:0: Label for a goto or gosub.  Only the first six
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.            characters of a label name are used, the rest are
  1460.            ignored.  So the compiler will see fredscum and
  1461.            fredscum2 as the same label.
  1462.  
  1463. return :N:5: Continue execution at the instruction following a
  1464.            gosub.  If no gosub was ever called, start at the
  1465.            beginning of the code.
  1466.  
  1467.              ----- Droid Control Instructions -----
  1468.  
  1469. delay :N:1: Delay, lets the cpu sit idle for the number of cycles
  1470.       specified in the x register.  Note the instruction takes
  1471.       one cycle itself to execute, so specifying a delay of 1
  1472.       would actually delay 2 cpu cycles.
  1473.  
  1474. radar :X:20: This is the instructions to use to find other
  1475.       droids.  The instruction uses the number in the x register
  1476.       as the direction to scan, and the number in the y register
  1477.       as a beam width.  The beam width is measured from the scan
  1478.       angle to both sides.  Thus if the beam width is five
  1479.       degrees, any droid that is less than five degrees left or
  1480.       right of the scan angle will be seen.  The distance to this
  1481.       droid will be placed into the x register.  If more than one
  1482.       other droid exists within the scan beam, the closest
  1483.       distance is put in the x register.  If no other droid
  1484.       exists within the beam, a -1 is put in the x register.
  1485.  
  1486. radar0 :X:10: This instructions is a shortened version of the
  1487.       radar instruction.  It automatically assumes a beam width
  1488.       of 0 degrees.  It requires the scan angle to be in the x
  1489.       register.  It replaces the x register with the distance to
  1490.       the closest droid in the scan direction, or -1 if there is
  1491.       no droid in the scan direction.  The advantage of this
  1492.       instruction over radar is that it takes much less time to
  1493.       execute, so your droid runs much faster.  If your droid
  1494.       executes the following:
  1495.  
  1496.            #60  radar0
  1497.  
  1498.       the distance to the other droid will be put in the x
  1499.       register. The following diagram should help explain this:
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.          90  degrees
  1526.  
  1527.               |                /
  1528.               |               /
  1529.               |             _/__
  1530.               |            /other\
  1531.               |           |       |
  1532.               |            \droid/
  1533.               |          /
  1534.               |         /       The other droid will be seen, 
  1535.               |        /      and its distance to the scanning 
  1536.               |       /       droid will be put into the x 
  1537.               |      /        register of the scanning droid.
  1538.               |     /         (This will replace the scanning
  1539.               |    /          originally in x).
  1540.             _____ /       An angle of about 60 degrees in
  1541.            /scan-\        the x register.
  1542.           | ning  | ----------------------------   0 degrees ----
  1543.            \droid/
  1544.  
  1545. radarw :X:10: This is a different form of radar beam.  Instead of
  1546.       a cone, the beam is a rectangle.  See the diagram below
  1547.       for an example of this.  In the x register is the scan 
  1548.       angle as with all radar instructions.  In the y register
  1549.       is the beam width measured in meters.  Droids are 4 meters
  1550.       across.  So the diagram below is for a beam width of 4.
  1551.       The instructions to execute this would be:
  1552.  
  1553.         # 4, # 60, radarw
  1554.  
  1555.       As with all radar instructions, the number in the x
  1556.       register is replaced with the distance to the closest
  1557.       droid in the beam, or -1 if there are no droids in the
  1558.       beam.
  1559.           90  degrees
  1560.                            
  1561.               |     ---> / beam  / <---
  1562.               |         / width /
  1563.               |        /     _ /__
  1564.               |       /     /other\
  1565.               |      /     |       |
  1566.               |     /       \droid/
  1567.               |    /       /
  1568.               |   /       /     The other droid will be seen, 
  1569.               |  /       /    and its distance to the scanning 
  1570.               | /       /     droid will be put into the x 
  1571.               |/       /      register of the scanning droid.
  1572.               |       /       
  1573.              /|      /     A width of 4 meters in the y register,
  1574.             /_____  /      and an angle of about 60 degrees in
  1575.            /scan-\ /       the x register.
  1576.           | ning  | ----------------------------   0 degrees ----
  1577.            \droid/
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593. fire n :N:25: This attempts to fire weapon number n.  If the
  1594.        weapon is still operating (has not received damage
  1595.        sufficient to destroy it), and has ammunition remaining,
  1596.        and it has reloaded, it will fire.  If firing a gun or
  1597.        rocket from a rail, the x register is used to tell the
  1598.        shot how far to go before exploding. Thus, even if you can
  1599.        not get a direct hit on anotherdroid, you may be able to
  1600.        cause some damage from a nearmiss.  If the weapon is an
  1601.        instantaneous weapon such as a laser, it will not explode
  1602.        at a given distance.  If it does not score a direct hit,
  1603.        it will hit a wall.  Before a weapon may fire again, it
  1604.        must reload.  The time required to reload varies between
  1605.        weapons, and is listed under the hardware section.
  1606.  
  1607. heading :N:5: Use the number in the x register as the new
  1608.         direction to go (in degrees).
  1609.  
  1610. speed :N:5: Use the number in the x register as the new speed.
  1611.  
  1612. aim :N:12: Use the number in the x register as the new direction
  1613.     to point the turret.  0 degrees is straight right, posative
  1614.     is measured counter closckwise.
  1615.  
  1616. xmit channel :N:7: Transmit. This can be used to communicate
  1617.              between droids.  There are five different channels
  1618.              to transmit on.  Thus channel is a number 0-4.  This
  1619.              transmits the number in the x register to all other
  1620.              droids.  All droids will receive this number on the
  1621.              channel specified.  If a droid knows what to do with
  1622.              this number, it will do what its programming
  1623.              requests it to do.  If a droid does not understand
  1624.              it, or never looks at it, it may do nothing.
  1625.  
  1626. recv n :P:7: Put the number that has latest been received on
  1627.        channel n in the x register.
  1628.  
  1629. destruct :N:20: This is a desperation command.  If you know you
  1630.          are about to die, and want to take a few others with
  1631.          you, you can self destruct.
  1632.  
  1633. concede :N:20: This is an easy way out.  If you don't want anyone
  1634.          else to get any more points by punching you, you may
  1635.          concede.  This removes your droid from the arena
  1636.          immediately.
  1637.  
  1638.            ----- Droid Environment Instructions -----
  1639.                                                   
  1640. posx :P:15: Put the x position (from 0 to 100 meters) in the x
  1641.      register.  x is measured starting from the left (0) to the
  1642.      right.  The right wall is at 100 meters.
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657. posy :P:15: Put the y position (from 0 to 100 meters) in the x
  1658.      register.  y is measured starting from the bottom (0) to the
  1659.      top.  The top wall is at 100 meters.
  1660.  
  1661. time :P:2: Push the stack up, and put the current game time in
  1662.      the x register. Game time starts at 0 when the battle
  1663.      starts and is incremented every 1/10 second.
  1664.  
  1665. dsts :U:10: Drive status.  Puts information about the drive in
  1666.      the stack:
  1667.        x: total armor remaining
  1668.        y: current speed
  1669.        z: current heading
  1670.  
  1671. wsts n :U:10: Weapon status.  Puts information about weapon
  1672.        number n in the
  1673.          stack:
  1674.          x: total armor remaining
  1675.          y: ammo left
  1676.          z: time of last firing
  1677.  
  1678. hit :P:5: If the droid has been hit since this command was last
  1679.      called, return a 1 to the x register, if not, return a 0.
  1680.  
  1681.  
  1682.  
  1683.  
  1684. note well: If your droid messes up, like dividing by 0, or trying
  1685. to access a storage register that doesn't exist, it will lock up.
  1686. It will stop executing instructions,  and just sit there, or keep
  1687. going where it was headed (inertia, see Newton).  Just a friendly
  1688. warning.
  1689.  
  1690.  
  1691.  
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.                8 :  Example Droid Program, Arthur
  1724.  
  1725.  
  1726.  
  1727.  
  1728. drive hover 100   \ give it a hover drive with 100 extra armor \
  1729. cpu 32bit         \ make it think well. \
  1730. reg 5             \ only need a few storage registers. \
  1731. weap laser 30 70  \ give it a laser with 30 armor and 100 shots \
  1732. weap hgun 30 70   \ and a lgun with 30 armor and 70 shots \
  1733.                   \ note since the laser was defined first, it \
  1734.                   \ is weapon 0, and the lgun is 1 \
  1735.  
  1736. equate width 0    \ everywhere "width" is seen, it is replaced \
  1737.                   \ with "0" \
  1738. equate angle 1
  1739. equate dist  6
  1740. equate run   4
  1741.  
  1742.  
  1743. lab start        \ where to come back to when starting again \
  1744. # 0 speed        \ make sure it's not going anywhere \
  1745. sto 7            \ speed command does not change x, so 0 \
  1746.                  \ is stored in register 7 \
  1747. # 50, posy, -, enter, # 50, posx, -, atan2, # 90, -, sto run
  1748.                  \ direction to go when running away. \
  1749. # 90
  1750. sto width     \ reg 0 holds beam width \
  1751. sto angle     \ reg 1 holds angle looking at \
  1752.  
  1753. lab scan
  1754. hit           \ see if it gets hit while looking \
  1755. x!=0?         \ if it does, move \
  1756. goto move
  1757. rcl width     \ recall the beam width \
  1758. rcl angle     \ recall the scan angle \
  1759. radar         \ anyone out there? \
  1760. x>0?          \ found something \
  1761. sto dist      \ store distance \
  1762. x>0?
  1763. goto sam
  1764. rcl width
  1765. # 2 *                    
  1766. sto+ angle        \ add it \
  1767.  
  1768. lab sam       \ found something \
  1769. # 2
  1770. sto/ width        \ half the beam width \
  1771. rcl width
  1772. sto- angle    \ take new width from scan angle \
  1773. # .6
  1774. x<y?          \ if width is less than .6, start firing. \
  1775. goto scan
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790. # 2, rcl dist, /, atan    \ shoot to the left a bit \
  1791. rcl angle, +, aim
  1792.  
  1793. lab fire
  1794. hit
  1795. x!=0? 
  1796. goto move
  1797. rcl dist
  1798. fire 0        \ fire the laser \
  1799. fire 1        \ fire the gun \
  1800. # .8          \ beam width is put in x \
  1801. rcl angle     \ rcl pushes stack up, so beam width is now in y,\
  1802.               \ and recalled number is in x \
  1803. radar         \ is it still there ? \
  1804. x<0? goto start  \ find it again if arthur lost it \
  1805. sto dist         \ save the distance in case the target moved \
  1806. goto fire        \ otherwise keep firing \
  1807.  
  1808.  
  1809. lab move
  1810. # 20             \ run away!!! \
  1811. speed
  1812. rcl run
  1813. heading
  1814. # 20
  1815. sto+ run         \ change direction to run each time \
  1816. # 50 delay       \ a delay \
  1817. # 0 speed        \ and stop \
  1818. goto start       \ find something to shoot \
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.